<template>
    <!-- vue3页面 -->
    
    <div> 
        <el-button @click="add">添加数据</el-button>
        <el-button @click="del">删除数据</el-button>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="id" label="id" width="180" />
            <el-table-column prop="date" label="Date" width="180" />
            <el-table-column prop="name" label="Name" width="180" />
            <el-table-column label="choose">
                <template #default="scope">
                    <el-checkbox>{{scope.row.name}}</el-checkbox>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="Address" />
        </el-table>
    </div>
</template>

<script lang='ts'>
import { defineComponent, reactive, ref } from 'vue'
export default defineComponent({
    name: 'App',
    setup() {
        let tableData:any = ref([
            {
                id:'1',
                date: '2016-05-03',
                name: 'Tom',
                address: 'No. 189, Grove St, Los Angeles',
            },
            {
                id:'2',
                date: '2016-05-02',
                name: 'Tom',
                address: 'No. 189, Grove St, Los Angeles',
            },
            {
                id:'3',
                date: '2016-05-04',
                name: 'Tom',
                address: 'No. 189, Grove St, Los Angeles',
            },
            {
                id:'4',
                date: '2016-05-01',
                name: 'Tom',
                address: 'No. 189, Grove St, Los Angeles',
            },
        ])
        let addData = [
            {
                id:'5',
                date: '2016-05-01',
                name: '尚艳东',
                address: 'No. 189, Grove St, Los Angeles',
            }
        ]
        let delData = [
            {
                id:'3',
                date: '2016-05-01',
                name: '尚艳东',
                address: 'No. 189, Grove St, Los Angeles',
            }
        ]
        const add =()=>{
            console.log('add')
            tableData.value = tableData.value.concat(addData)
            
            console.log(tableData,'tabledata')
        }
        const del =()=>{
            console.log('del')
            for(let i=0;i<delData.length;i++){
                let id1 = tableData.value.findIndex((item:any) => {
                    if (item.id == delData[i].id) {
                        return true
                    }
                })
                console.log(id1,'id11')
                if(id1!==-1){
                    tableData.value.splice(id1, 1)
                }else{
                    alert('没有此数据')
                }
                
            }
            
        }
        return {
            tableData,
            add,
            del
        }
    }
})
</script>

<style scoped>

</style>